home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 7_5.lha / 7_5 / 7_5bline.c < prev    next >
Text File  |  1993-08-08  |  724b  |  31 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. / Exercise 7.5
  6. / rectangle derived from a line
  7. lass line : public rectangle
  8.  
  9.    point &w() { return sw; }
  10.    point &e() { return ne; }
  11.  
  12. ublic:
  13.    point north()
  14. { return point((w().x+e().x)/2,
  15.                e().y<w().y?w().y:e().y); }
  16.    point east();
  17.    point south()
  18. { return point((w().x+e().x)/2, 
  19.                e().y<w().y?e().y:w().y); }
  20.    point west();
  21.  
  22.    void move(int a, int b)
  23. { w().x += a; w().y += b; 
  24.   e().x += a; e().y += b; }
  25.    void draw() { put_line(w(),e()); }
  26.  
  27.    line(point a, point b) : (a, b) { }
  28.    line(point a, int l) : 
  29. ( point(a.x+l-1,a.y), a) { }
  30. ;
  31.